﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Util.Model;
using YiSha.Entity;
using YiSha.Model;
using YiSha.Admin.Web.Controllers;
using YiSha.Entity.YiDongYuan;
using YiSha.Business.YiDongYuan;
using YiSha.Model.Param.YiDongYuan;

namespace YiSha.Admin.Web.Areas.YiDongYuan.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2021-06-19 14:56
    /// 描 述：检测人员所要检测的设备控制器类
    /// </summary>
    [Area("YiDongYuan")]
    public class DetectionUserDeviceController :  BaseController
    {
        private DetectionUserDeviceBLL detectionUserDeviceBLL = new DetectionUserDeviceBLL();

        #region 视图功能
        [AuthorizeFilter("yidongyuan:detectionuserdevice:view")]
        public ActionResult DetectionUserDeviceIndex()
        {
            return View();
        }

        public ActionResult DetectionUserDeviceForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        [HttpGet]
        [AuthorizeFilter("yidongyuan:detectionuserdevice:search")]
        public async Task<ActionResult> GetListJson(DetectionUserDeviceListParam param)
        {
            TData<List<DetectionUserDeviceEntity>> obj = await detectionUserDeviceBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("yidongyuan:detectionuserdevice:search")]
        public async Task<ActionResult> GetPageListJson(DetectionUserDeviceListParam param, Pagination pagination)
        {
            TData<List<DetectionUserDeviceEntity>> obj = await detectionUserDeviceBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        public async Task<ActionResult> GetFormJson(long id)
        {
            TData<DetectionUserDeviceEntity> obj = await detectionUserDeviceBLL.GetEntity(id);
            return Json(obj);
        } 
        [HttpGet]
        public async Task<ActionResult> GetFormJsonByUserId(long userId)
        {
            TData<DetectionUserDeviceEntity> obj = await detectionUserDeviceBLL.GetEntityByUserId(userId);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("yidongyuan:detectionuserdevice:add,yidongyuan:detectionuserdevice:edit")]
        public async Task<ActionResult> SaveFormJson(DetectionUserDeviceEntity entity)
        {

            TData<string> obj = await detectionUserDeviceBLL.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("yidongyuan:detectionuserdevice:delete")]
        public async Task<ActionResult> DeleteFormJson(string ids)
        {
            TData obj = await detectionUserDeviceBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}
